import 'dart:collection';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gif/gif.dart';
import '../bean/TravelBean.dart';
import '../config/AppConst.dart';
import '../generated/l10n.dart' as language;
import '../utils/AudioUtils.dart';
import '../utils/CommUtils.dart';
import '../utils/SpUtils.dart';
import '../view/_OverScrollBehavior.dart';
import 'dart:math' as math;
import '../pages/HomePage.dart';
import '../pages/TravelGamePage.dart';
import '../routers/router.dart';
import 'My.dart';

const numlist = [
  "assets/num/a-0.png",
  "assets/num/a-1.png",
  "assets/num/a-2.png",
  "assets/num/a-3.png",
  "assets/num/a-4.png",
  "assets/num/a-5.png",
  "assets/num/a-6.png",
  "assets/num/a-7.png",
  "assets/num/a-8.png",
  "assets/num/a-9.png",
];

const numlist2 = [
  "assets/num/b-0.png",
  "assets/num/b-1.png",
  "assets/num/b-2.png",
  "assets/num/b-3.png",
  "assets/num/b-4.png",
  "assets/num/b-5.png",
  "assets/num/b-6.png",
  "assets/num/b-7.png",
  "assets/num/b-8.png",
  "assets/num/b-9.png",
];

class Travel1 extends StatefulWidget {
  Travel1({Key? key}) : super(key: key);
  @override
  State<Travel1> createState() => Travel1State();
}

class Travel1State extends State<Travel1> with SingleTickerProviderStateMixin {
  int max = 12; //这必须是偶数 下面的middleImgs必须是一半
  bool isright = true; //true右边图片
  int themeCount = 36; //36个主题

//中间的大图集合  注意数量是max的一半
  List<TravelBean> imgsList = [];

  List<TravelBean> list = [];
  ScrollController? _scrollController;
  @override
  void initState() {
    _scrollController = ScrollController();
    isright = true;
    list.clear();
    grade = CommUtils.getGrade();
    //获取当前主题的插画
    var trvelgrade =
        SpUtils.getInstance()?.getString('$AppConst.trvelgrade$grade');
    if (trvelgrade != null) {
      List list = json.decode(trvelgrade);
      imgsList = list.map((e) => TravelBean.fromJson(e)).toList();
    }
    print("imglsit:${imgsList.length}");
    //以免重复
    HashMap<int, int> map = HashMap();
    for (int i = max; i >= 1; i--) {
      //   currenti = max;
      if (i % 2 == 1) {
        var travelBean = TravelBean();
        travelBean.bottomNum = i;
        travelBean.topNum = i + 1;
        travelBean.topNumimg = "assets/images/travel_num.png";
        travelBean.bottomNumimg = "assets/images/travel_num.png";

        if (i == 1) {
          //最后一个
          travelBean.type = 4;
          travelBean.bgImg = "assets/images/travel_bottom.png";
          travelBean.rightImg = false;
        } else if (i == max - 1) {
          //第一个
          travelBean.type = 1;
          travelBean.rightImg = true;
          travelBean.bgImg = "assets/images/travel_top.png";
        } else {
          if (isright) {
            travelBean.type = 2;
            travelBean.rightImg = false;
            travelBean.bgImg = "assets/images/travel_right.png";
            isright = false;
          } else {
            travelBean.type = 3;
            travelBean.rightImg = true;
            travelBean.bgImg = "assets/images/travel_left.png";
            isright = true;
          }
        }
        if (trvelgrade == null) {
          //获取插图随机
          var nextInt = math.Random().nextInt(IllustrationList.length);
          if (map[nextInt] == null) {
            travelBean.sceneryImg = IllustrationList[nextInt];
            map[nextInt] = nextInt;
          } else {
            while (true) {
              var nextInt = math.Random().nextInt(IllustrationList.length);
              if (map[nextInt] == null) {
                travelBean.sceneryImg = IllustrationList[nextInt];
                map[nextInt] = nextInt;
                break;
              }
            }
          }

          imgsList.add(travelBean);
        }

        list.add(travelBean);
      }
    }
    if (trvelgrade == null) {
      SpUtils.getInstance()
          ?.setString('$AppConst.trvelgrade$grade', json.encode(imgsList));
    }

    super.initState();
  }

  var grade;
  @override
  Widget build(BuildContext context) {
    //当前等级
    grade = CommUtils.getGrade();
    //grade = 9;
    var width = CommUtils.getWidth(context);
    var hight = CommUtils.getHeight(context);

    return ScrollConfiguration(
      behavior: OverScrollBehavior(), //干掉上拉下啦有波浪纹
      child: Stack(
        children: [
          Image.asset(
            'assets/images/tab_bg.png',
            fit: BoxFit.fill,
            width: double.infinity,
            height: double.infinity,
          ),
          Row(
            // 插图和轨道居中显示
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Container(
                padding: EdgeInsets.only(left: 20, right: 20),
                width: CommUtils.getISWidth(width, hight) ? hight * 0.6 : width,
                alignment: Alignment.center,
                child: ListView(
                  reverse: true, //1.设置倒序为true
                  shrinkWrap: true, //2.ListView在容器无限时设置为true
                  // padding: EdgeInsets.only(
                  //     //  top: 5,
                  //     //   bottom: 5,
                  //     left: ScreenUtil().setWidth(width * 0.10),
                  //     right: ScreenUtil().setWidth(width * 0.1)),
                  controller: _scrollController, //滚动到底部
                  children: [
                    Stack(
                      children: [
                        //插画
                        ListView.builder(
                            padding: EdgeInsets.all(0),
                            // padding: EdgeInsets.all(10),
                            // controller: ScrollController(), //滚动到底部
                            itemBuilder: (context, index) {
                              return getImgItem(imgsList[index]);
                            },
                            shrinkWrap: true, //解决无限高度问题
                            physics:
                                new NeverScrollableScrollPhysics(), //禁用滑动事件，否则和 外部ListView冲突
                            itemCount: imgsList.length),
                        //轨道

                        ListView.builder(
                            padding: EdgeInsets.all(0),
                            //  padding: EdgeInsets.all(10),
                            controller: _scrollController, //滚动到底部
                            itemBuilder: (context, index) {
                              return getTravel(list[index], grade);
                            },
                            shrinkWrap: true, //解决无限高度问题 必须设置
                            physics:
                                new NeverScrollableScrollPhysics(), //禁用滑动事件 否则和 ListView冲突
                            //  scrollDirection: Axis.vertical,
                            itemCount: list.length),
                      ],
                    ),
                  ],
                ),
              ),
            ],
          )
        ],
      ),
    );
  }

/**
 * 弹窗
 */
  Widget showDilog() {
    return Container(
      height: ScreenUtil().setHeight(330),
      width: CommUtils.getWidth(context) - ScreenUtil().setWidth(42),
      decoration: BoxDecoration(
        image: DecorationImage(
            image: AssetImage('assets/images/bg_seting.png'), fit: BoxFit.fill),
      ),
      child: Padding(
        padding: EdgeInsets.only(
            left: ScreenUtil().setWidth(40),
            top: ScreenUtil().setHeight(35),
            right: ScreenUtil().setWidth(40),
            bottom: 32),
        child: Column(
          children: [
            CommUtils.getTextString(
                context,
                language.S.of(context).congratulations_you,
                20,
                true,
                1,
                Colors.white),
            SizedBox(
              height: ScreenUtil().setHeight(15),
            ),
            Image.asset('assets/illustration/Illustration_reset.png',
                width: ScreenUtil().setWidth(197.5),
                height: ScreenUtil().setWidth(102),
                fit: BoxFit.fitHeight),
            SizedBox(
              height: ScreenUtil().setHeight(15),
            ),
            Container(
              width: ScreenUtil().setWidth(170),
              child: CommUtils.getTextString(
                  context,
                  language.S.of(context).reset_all_travel,
                  15,
                  false,
                  2,
                  Colors.white),
            ),
            Expanded(child: SizedBox()),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                GestureDetector(
                  onTap: () {
                    AudioUtils.getInstance()?.play2("start_game.mp3");
                    AudioUtils.getInstance()?.stopHomeBGm();
                    //点击好的
                    SpUtils?.getInstance()?.setInt(AppConst.theme, 1);
                    SpUtils?.getInstance()?.setInt(AppConst.grade, 1);
                    SpUtils?.getInstance()
                        ?.setString(AppConst.travelrandomList, '');
                    SpUtils.getInstance()
                        ?.setString(AppConst.trvelContinueGame, '');
                    //再这里关闭，放到后面打不开界面
                    Navigator.pop(context);
                    startPageDown2(
                      context,
                      TravelGamePage(),
                      calllBack: (selectIndex) => setState(() {}),
                    );
                    setState(() {});
                  },
                  child: Container(
                      height: ScreenUtil().setHeight(36.5),
                      width: ScreenUtil().setWidth(90),
                      decoration: BoxDecoration(
                        image: DecorationImage(
                          image: AssetImage('assets/images/new_game.png'),
                          fit: BoxFit.fill,
                        ),
                      ),
                      alignment: Alignment.center,
                      child: Padding(
                          padding: EdgeInsets.only(
                              top: 5, bottom: 7, right: 5, left: 5),
                          child: CommUtils.getTextGame(
                            context,
                            15,
                            language.S.of(context).good_2,
                            colorList[0],
                            colorList[1],
                          ))),
                ),
                GestureDetector(
                  onTap: () {
                    Navigator.pop(context);
                  },
                  child: Container(
                      height: ScreenUtil().setHeight(36.5),
                      width: ScreenUtil().setWidth(90),
                      decoration: BoxDecoration(
                        image: DecorationImage(
                          image: AssetImage('assets/images/new_game.png'),
                          fit: BoxFit.fill,
                        ),
                      ),
                      alignment: Alignment.center,
                      child: Padding(
                          padding: EdgeInsets.only(
                              top: 5, bottom: 7, right: 5, left: 5),
                          child: CommUtils.getTextGame(
                            context,
                            15,
                            language.S.of(context).no_,
                            colorList[0],
                            colorList[1],
                          ))),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }

  double imgWidth = 0.45;
  double imgPading = 0.1; //插图左右边距
  Widget getImgItem(TravelBean item) {
    Size scurel = MediaQuery.of(context).size;
    double size;
    if (CommUtils.getISWidth(scurel.width, scurel.height)) {
      size = CommUtils.getHeight(context) * 0.6;
    } else {
      size = CommUtils.getWidth(context);
    }

    if (item.type == 4) {
      //插图底部图片  间距
      return Container(
        width: double.infinity,
        height: size * _bottomHight,
        padding: EdgeInsets.only(top: size * 0.2,left: size * imgPading),
        alignment: Alignment.topLeft,
        child: Image.asset(item.sceneryImg,
            width: size * imgWidth, fit: BoxFit.contain),
      );
    } else if (item.type == 1) {
      //插图顶部图片间距
      return Container(
        width: double.infinity,
        padding: EdgeInsets.only(right: size * imgPading),
        //  padding: EdgeInsets.only(top: ScreenUtil().setHeight(100)),
        height: size * _topHight + size * 0.08, //底部高度不够，加上25刚好
        alignment: Alignment.bottomRight,
        child: Image.asset(item.sceneryImg,
            width: size * imgWidth, fit: BoxFit.contain),
      );
    } else {
      if (item.rightImg) {
        return getImgRight(item);
      } else {
        return getImgLeft(item);
      }
    }
  }

  Widget getImgLeft(TravelBean item) {
    Size scurel = MediaQuery.of(context).size;
    double size;
    if (CommUtils.getISWidth(scurel.width, scurel.height)) {
      size = CommUtils.getHeight(context) * 0.6;
    } else {
      size = CommUtils.getWidth(context);
    }
//插图左边图片
    return Container(
      padding: EdgeInsets.only(top: size * 0.2, left: size * imgPading),
      width: double.infinity,
      height: size * _normalHight,
      alignment: Alignment.topLeft,
      child: Image.asset(item.sceneryImg,
          width: size * imgWidth, fit: BoxFit.contain),
    );
  }

  Widget getImgRight(TravelBean item) {
    Size scurel = MediaQuery.of(context).size;
    double size;
    if (CommUtils.getISWidth(scurel.width, scurel.height)) {
      size = CommUtils.getHeight(context) * 0.6;
    } else {
      size = CommUtils.getWidth(context);
    }

    //插图右边图片
    return Container(
       padding: EdgeInsets.only(top: size * 0.2, right: size * imgPading),
      width: double.infinity,
      height: size * _normalHight,
      alignment: Alignment.topRight,
      child: Image.asset(item.sceneryImg,
          width: size * imgWidth, 
          fit: BoxFit.contain),
    );
  }

//list  Item
  Widget getTravel(TravelBean item, int grade) {
    if (item.type == 1) {
      //顶部
      return _getTop(item, grade);
    } else if (item.type == 4) {
      return _getBottom(item, grade);
    } else if (item.type == 3) {
      return _getLeft(item, grade);
    } else {
      return _getRigt(item, grade);
    }
  }

  double pading = 0.03;
  double leftRightPading = 0.04; //数字左右边距
/**
 * 顶部轨道
 */
  Widget _getTop(TravelBean item, int grade) {
    Size scurel = MediaQuery.of(context).size;
    double size;
    if (CommUtils.getISWidth(scurel.width, scurel.height)) {
      size = CommUtils.getHeight(context) * 0.6;
    } else {
      size = CommUtils.getWidth(context);
    }
    return Container(
      width: double.infinity,
      height: size * _topHight,
      alignment: Alignment.centerLeft,
      child: Stack(
        children: [
          Align(
            alignment: Alignment.center,
            child: Padding(
              // 和下面进度条一致
              padding: EdgeInsets.only(
                left: size * pading,
                right: size * pading,
              ),
              child: Image.asset(item.bgImg,
                  height: double.infinity, fit: BoxFit.fill),
            ),
          ),
          //进度条

          Align(
            alignment: Alignment.center,
            child: Padding(
              // 和上面一致
              padding: EdgeInsets.only(
                left: size * pading,
                right: size * pading,
              ),
              child: getGrade(grade, item),
            ),
          ),

          Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(
                left: size * leftRightPading,
              ),
              child: _getNumText(item, item.topNum, grade),
            ),
          ),

          Align(
            alignment: Alignment.bottomLeft,
            child: Padding(
              padding: EdgeInsets.only(
                left: size * leftRightPading,
              ),
              child: _getNumText(item, item.bottomNum, grade),
            ),
          ),
        ],
      ),
    );
  }

//底部高度
  double _bottomHight = 0.945;
//中间高度
  double _normalHight = 0.5;
  //底部高度
  double _topHight = 0.49;

  /**
 * 底部轨道
 */
  Widget _getBottom(TravelBean item, int grade) {
    Size scurel = MediaQuery.of(context).size;
    double size;
    if (CommUtils.getISWidth(scurel.width, scurel.height)) {
      size = CommUtils.getHeight(context) * 0.6;
    } else {
      size = CommUtils.getWidth(context);
    }
    return Container(
      height: size * _bottomHight,
      alignment: Alignment.centerLeft,
      child: Stack(
        children: [
          Align(
            alignment: Alignment.center,
            child: Padding(
              padding: EdgeInsets.only(
                left: size * pading,
                right: size * pading,
                bottom: size * 0.042,
              ),
              child: Image.asset(item.bgImg,
                  height: double.infinity, fit: BoxFit.fill),
            ),
          ),

          //进度条
          Align(
            alignment: Alignment.center,
            child: Padding(
              padding: EdgeInsets.only(
                left: size * pading,
                right: size * pading,
                bottom: size * 0.042,
              ),
              child: getGrade(grade, item),
            ),
          ),

          Align(
              alignment: Alignment.topCenter,
              child: Padding(
                padding: EdgeInsets.only(top: size * 0.04),
                child: _getNumText(item, item.topNum, grade),
              )),
          //底部右边
          Align(
            alignment: Alignment.centerRight,
            child: Padding(
              padding: EdgeInsets.only(
                right: size * leftRightPading,
                bottom: size * 0.16,
              ),
              child: _getNumText(item, item.bottomNum, grade),
            ),
          ),

          //底边
          Align(
            alignment: Alignment.bottomCenter,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                    margin: EdgeInsets.only(left: size * 0.02),
                    width: size * 0.2,
                    height: size * 0.2,
                    decoration: BoxDecoration(
                      image: DecorationImage(
                        image: AssetImage(item.bottomNumimg),
                        fit: BoxFit.contain,
                      ),
                    ),
                    alignment: Alignment.center,
                    child: Padding(
                      padding: EdgeInsets.only(
                          top: size * 0.025, right: 5, bottom: 5, left: 5),
                      child: CommUtils.getTextGame(
                          context,
                          22,
                          language.S.of(context).travel_,
                          Color(0Xff98E7FF),
                          Color(0Xff919397)),
                    ))
              ],
            ),
          ),
          //底部完
        ],
      ),
    );
  }

  /**
   * 进度条
   */
  Widget getGrade(int grade, TravelBean item) {
    if (item.type == 4) {
      //底部
      if (grade > item.topNum) {
        return Image.asset("assets/images/grade3.png",
            height: double.infinity, fit: BoxFit.fill);
      } else if (grade == item.topNum) {
        return Image.asset("assets/images/grade2.png",
            height: double.infinity, fit: BoxFit.fill);
      } else {
        return Image.asset("assets/images/grade1.png",
            height: double.infinity, fit: BoxFit.fill);
      }
    } else if (item.type == 1) {
      //顶部
      if (grade == max) {
        return Image.asset("assets/images/grade_top.png",
            height: double.infinity, fit: BoxFit.fill);
      } else {
        return Container();
      }
    } else if (item.type == 2) {
      // 右小角进
      if (grade > item.topNum) {
        return Image.asset("assets/images/grade_right2.png",
            height: double.infinity, fit: BoxFit.fill);
      } else if (grade == item.topNum) {
        return Image.asset("assets/images/grade_right1.png",
            height: double.infinity, fit: BoxFit.fill);
      } else {
        return Container();
      }
    } else if (item.type == 3) {
      // 左下角进
      if (grade > item.topNum) {
        return Image.asset("assets/images/grade_left2.png",
            height: double.infinity, fit: BoxFit.fill);
      } else if (grade == item.topNum) {
        return Image.asset("assets/images/grade_left1.png",
            height: double.infinity, fit: BoxFit.fill);
      } else {
        return Container();
      }
    } else {
      return Container();
    }
  }

  /**
 * 左边的轨道
 */
  Widget _getLeft(TravelBean item, int grade) {
    Size scurel = MediaQuery.of(context).size;
    double size;
    if (CommUtils.getISWidth(scurel.width, scurel.height)) {
      size = CommUtils.getHeight(context) * 0.6;
    } else {
      size = CommUtils.getWidth(context);
    }
    return Container(
      width: double.infinity,
      height: size * _normalHight,
      alignment: Alignment.centerLeft,
      child: Stack(
        children: [
          Align(
            alignment: Alignment.center,
            child: Padding(
              padding: EdgeInsets.only(
                left: size * pading,
                right: size * pading,
              ),
              child: Image.asset(item.bgImg,
                  height: double.infinity, fit: BoxFit.fill),
            ),
          ),
          Align(
            //进度条
            alignment: Alignment.center,
            child: Padding(
              padding: EdgeInsets.only(
                left: size * pading,
                right: size * pading,
              ),
              child: getGrade(grade, item),
            ),
          ),

          //上面的
          Align(
              alignment: Alignment.topCenter,
              child: Padding(
                padding: EdgeInsets.only(top: size * 0.055),
                child: _getNumText(item, item.topNum, grade),
              )),

          Align(
              alignment: Alignment.bottomLeft,
              child: Padding(
                padding: EdgeInsets.only(left: size * leftRightPading),
                child: _getNumText(
                  item,
                  item.bottomNum,
                  grade,
                ),
              )),
        ],
      ),
    );
  }

  /**
 * 右边的轨道
 */
  Widget _getRigt(TravelBean item, int grade) {
    Size scurel = MediaQuery.of(context).size;
    double size;
    if (CommUtils.getISWidth(scurel.width, scurel.height)) {
      size = CommUtils.getHeight(context) * 0.6;
    } else {
      size = CommUtils.getWidth(context);
    }
    return Container(
      width: size,
      height: size * _normalHight,
      alignment: Alignment.centerLeft,
      child: Stack(
        children: [
          Align(
            alignment: Alignment.center,
            child: Padding(
              padding: EdgeInsets.only(
                left: size * pading,
                right: size * pading,
              ),
              child: Image.asset(item.bgImg,
                  height: double.infinity, fit: BoxFit.fill),
            ),
          ),

          //进度条
          Align(
            alignment: Alignment.center,
            child: Padding(
              padding: EdgeInsets.only(
                left: size * pading,
                right: size * pading,
              ),
              child: getGrade(grade, item),
            ),
          ),

          Align(
              alignment: Alignment.topCenter,
              child: Padding(
                padding: EdgeInsets.only(top: size * 0.07),
                child: _getNumText(
                  item,
                  item.topNum,
                  grade,
                ),
              )),
          Align(
              alignment: Alignment.bottomRight,
              child: Padding(
                padding: EdgeInsets.only(right: size * leftRightPading),
                child: _getNumText(
                  item,
                  item.bottomNum,
                  grade,
                ),
              )),
        ],
      ),
    );
  }

//数字布局 也在左边
  Widget _getNumText(TravelBean item, int num, int grade) {
    Size scurel = MediaQuery.of(context).size;
    double size;
    if (CommUtils.getISWidth(scurel.width, scurel.height)) {
      size = CommUtils.getHeight(context) * 0.6;
    } else {
      size = CommUtils.getWidth(context);
    }

    return Container(
      width: size * 0.2,
      height: size * 0.2,
      alignment: Alignment.center,
      child: GestureDetector(
        onTap: (() {
          //点击进入游戏
          if (grade != num) {
            return;
          }
          var theme = SpUtils.getInstance()?.getInt2(AppConst.theme);
          if (theme! > 36) {
            //弹窗
            showGeneralDialog(
                context: context,
                pageBuilder: (context, anim1, anim2) {
                  return Text("");
                },
                // barrierColor: Colors.grey.withOpacity(.4), // Dialog 的背景色
                barrierDismissible: true, //控制 Dialog 是否消失
                barrierLabel: "",
                transitionDuration: Duration(milliseconds: 200),
                transitionBuilder: (context, anim1, anim2, child) {
                  return Transform.scale(
                    scale: anim1.value,
                    child: Dialog(
                      backgroundColor: Colors.transparent,
                      child: showDilog(),
                    ),
                  );
                });
          } else {
            AudioUtils.getInstance()?.play2("start_game.mp3");
            AudioUtils.getInstance()?.stopHomeBGm();
            //旅行
            //
            startPageDown2(
              context,
              TravelGamePage(),
              calllBack: (selectIndex) => setState(() {}),
            );
          }
        }),
        child: Stack(
          children: [
            getBg(item, num, grade),
            Align(
                alignment: Alignment.center,
                child: getGradeNUm(num, grade, size)),
          ],
        ),
      ),
    );
  }

  Widget getGradeNUm(int num, int grade, double size) {
    if (grade == num) {
      return grade < 10
          ? Image.asset(
              //小于10的数字
              numlist[num],
              fit: BoxFit.contain,

              width: size * 0.04,
            )
          : Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Image.asset(
                  numlist[1],
                  fit: BoxFit.contain,
                  width: size * 0.04,
                ),
                Image.asset(
                  numlist[num - 10],
                  fit: BoxFit.contain,
                  width: size * 0.04,
                )
              ],
            );
    } else if (grade > num) {
      return num < 10
          ? Image.asset(
              //小于10的数字
              numlist2[num],
              fit: BoxFit.contain,
              width: size * 0.04,
            )
          : Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Image.asset(
                  numlist2[1],
                  fit: BoxFit.contain,
                  width: size * 0.04,
                ),
                Image.asset(
                  numlist2[num - 10],
                  fit: BoxFit.contain,
                  width: size * 0.04,
                )
              ],
            );
    } else {
      return Padding(
        padding: EdgeInsets.only(top: size * 0.015),
        child: CommUtils.getTextGame(
            context, 28, "${num}", Color(0Xff98E7FF), Color(0Xff919397)),
      );
    }
  }

/**
 * 获取背景图片
 */

  Widget getBg(
    TravelBean item,
    int num,
    int grade,
  ) {
    if (num > grade) {
      return Image.asset(item.topNumimg, fit: BoxFit.fill);
    } else if (num == grade) {
      return Gif(
        image: AssetImage("assets/gif/1.11.gif"),
        autostart: Autostart.loop,
      );
    } else {
      //已经完成的数字图片
      return Image.asset("assets/images/travel_commple.png",
          fit: BoxFit.contain);
    }
  }
}
